home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
modules
/
yoonoUtils.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
6KB
|
179 lines
var EXPORTED_SYMBOLS = ["YOONO_UTILS"];
// Vars
const YOONO_ID = "{d9284e50-81fc-11da-a72b-0800200c9a66}";
const MAGIC_URL = 'about:blank';
// Globals
const CI = Components.interfaces;
const CL = Components.classes;
const DIRSERVICE = CL['@mozilla.org/file/directory_service;1'].getService(CI.nsIProperties);
const PREFBRANCH = CL['@mozilla.org/preferences-service;1'].getService(CI.nsIPrefBranch);
const PREFSSERVICE = CL["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefService);
const PREFS = PREFSSERVICE.getBranch("extensions.yoono.");
const RDF = CL["@mozilla.org/rdf/rdf-service;1"].getService(CI.nsIRDFService);
const URL_RESOURCE = RDF.GetResource("http://home.netscape.com/NC-rdf#URL");
const FEED_URL_RESOURCE = RDF.GetResource("http://home.netscape.com/NC-rdf#FeedURL");
const LIVEBKM_TYPE = "http://home.netscape.com/NC-rdf#Livemark";
const LIVETAG = '.LIV';
function Utils() {
this.wrappedJSObject=this;
}
Utils.prototype.getExtensionVersion = function () {
var extmgr = CL['@mozilla.org/extensions/manager;1'].getService(CI.nsIExtensionManager);
return extmgr.getItemForID(YOONO_ID).version;
}
Utils.prototype.getUserAgent = function (win) {
return(win.navigator.userAgent.toLowerCase());
}
Utils.prototype.getUserAgentAppVersion = function (win) {
return(win.navigator.appVersion.toLowerCase());
}
Utils.prototype.getUserAgentOsCpu = function (win) {
return(win.navigator.oscpu.toLowerCase());
}
Utils.prototype.getUserAgentPlatform = function (win) {
return(win.navigator.platform.toLowerCase());
}
Utils.prototype.getLocale = function () {
return (PREFBRANCH.getCharPref('general.useragent.locale'));
}
Utils.prototype.stringException = function (e) {
return(e.toString);
}
// Return general debug info
Utils.prototype.dumpDebugInfo = function() {
var aDebugInfo = '################################################################################\n';
var appInfo = CL["@mozilla.org/xre/app-info;1"].getService(CI.nsIXULAppInfo);
aDebugInfo = aDebugInfo+'firefox version : '+appInfo.version+'\n';
aDebugInfo = aDebugInfo+'firefox build id : '+appInfo.appBuildID+'\n';
aDebugInfo = aDebugInfo+'yoono extension version : '+this.getExtensionVersion()+'\n';
aDebugInfo = aDebugInfo+'general.useragent.extra.firefox : '+PREFBRANCH.getCharPref('general.useragent.extra.firefox')+'\n';
aDebugInfo = aDebugInfo+'general.useragent.locale : '+PREFBRANCH.getCharPref('general.useragent.locale')+'\n';
aDebugInfo = aDebugInfo+'intl.accept_languages : '+PREFBRANCH.getCharPref('intl.accept_languages')+'\n';
// Affiche le chemin du rΘpertoire profile
aDebugInfo = aDebugInfo+'Profile directory : '+DIRSERVICE.get("ProfD",CI.nsIFile).path+'\n';
// Liste les prΘfΘrences yoono
aDebugInfo = aDebugInfo+'\nYoono preferences :\n';
var yoonoPrefChildren = PREFS.getChildList("", {});
for(var i in yoonoPrefChildren) {
if (yoonoPrefChildren[i] == "userid"){
aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : **********************\n';
}
else {
switch(PREFBRANCH.getPrefType('extensions.yoono.'+yoonoPrefChildren[i])) {
case CI.nsIPrefBranch.PREF_STRING: // PREF_STRING = 32
aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : '+PREFBRANCH.getCharPref('extensions.yoono.'+yoonoPrefChildren[i])+'\n';
break;
case CI.nsIPrefBranch.PREF_INT: // PREF_INT = 64
aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : '+PREFBRANCH.getIntPref('extensions.yoono.'+yoonoPrefChildren[i])+'\n';
break;
case CI.nsIPrefBranch.PREF_BOOL: // PREF_BOOL = 128
aDebugInfo = aDebugInfo+'extensions.yoono.'+yoonoPrefChildren[i]+' : '+PREFBRANCH.getBoolPref('extensions.yoono.'+yoonoPrefChildren[i])+'\n';
break;
}
}
}
// Liste les extensions installΘes
aDebugInfo = aDebugInfo+'\nFirefox extensions :\n';
var aExtManager = CL["@mozilla.org/extensions/manager;1"].getService(CI.nsIExtensionManager);
var aItemList = aExtManager.getItemList(CI.nsIUpdateItem.TYPE_ANY, { });
for(var i in aItemList) {
aDebugInfo = aDebugInfo+aItemList[i].name+', version='+aItemList[i].version+', update-url='+aItemList[i].updateRDF+'\n';
}
aDebugInfo = aDebugInfo+'################################################################################\n';
return aDebugInfo;
}
/*
@param str : une chaine qui represente le chemin
@return list : une liste qui represente le chemin
les chemins dans la chaine sont separes par des slash
les slashs qui font partie du nom de la chaine sont echappes
cela correspond a split(/(?!\\)\//)
qui semble ne pas marcher en javascript
ensuite, on desechappe les slash
*/
Utils.prototype.splitPath = function (str) {
// supprime le dernier caractere si c'est un '/' non precede d'un '\'
if (str.length != 1 && str[str.length - 1] == '/' && str[str.length - 2] != '\\') {
str = str.slice(0, -1);
}
var list = new Array();
var lastpos = 0;
var extract = '';
var l = str.length;
for (var pos = 0 ; pos <= l ; pos++) {
if ((str[pos] == '/' && str[pos - 1] != '\\') || pos == l) {
extract = str.slice(lastpos + 1,pos);
extract = extract.replace(/\\(\\|\/)/g,'$1');
list.push(extract);
lastpos = pos;
}
}
return list;
}
Utils.prototype.normalize = function (str) {
if (!str)
return str;
str = this.replaceIEInvalids(str);
str = str.replace(/[\s\.]*$/,'');
return str;
}
Utils.prototype.escapePath = function(name) {
if (!name) return '';
name = name.replace(/\\/g, '\\\\');
name = name.replace(/\//g, '\\/');
return name;
}
Utils.prototype.replaceIEInvalids = function (attribute) {
if (!attribute) return '';
attribute = attribute.replace(/\\|:|\*|\?|"|<|>|\|/g,'');
attribute = attribute.replace(/\//g, '-');
return attribute;
}
/*
@param list : une liste ou un objet
@return obj : une copie de la liste ou de l'objet
*/
Utils.prototype.copyObjectOrArray = function (list) {
// point final de la recursion
if (typeof list != 'object')
return list;
if (list.length === undefined)
var obj = new Object();
else
var obj = new Array();
for (var i in list)
obj[i] = this.copyObjectOrArray(list[i]);
return obj;
}
var YOONO_UTILS = new Utils();